package com.acme.bankapp.client;

import com.acme.bankapp.client.validator.Validator;
import com.acme.bankapp.client.validator.ValidatorFactory;

public class BankClientApp {

    public static void main(final String[] args) {
	BankClient client = new BankClient();
	applyCLIParams(args, client);
	client.run();
    }

    protected static void applyCLIParams(final String[] args,
	    final BankClient client) {
	Validator<String> ipAdressValidator = ValidatorFactory
		.createIPValidator();
	Validator<Integer> portValidator = ValidatorFactory
		.createPortValidator();
	if (args.length == 1
		&& portValidator.validate(Integer.valueOf(args[0]))) {
	    client.setServerPort(Integer.valueOf(args[0]));
	} else if (args.length == 2 && ipAdressValidator.validate(args[0])
		&& portValidator.validate(Integer.valueOf(args[1]))) {
	    client.setServerIP(args[0]);
	    client.setServerPort(Integer.valueOf(args[1]));
	}
    }
}
